package com.ruoyi.busi.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.core.page.PagePlus;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.busi.domain.bo.BusiCompanyGridBo;
import com.ruoyi.busi.domain.vo.BusiCompanyGridVo;
import com.ruoyi.busi.domain.BusiCompanyGrid;
import com.ruoyi.busi.mapper.BusiCompanyGridMapper;
import com.ruoyi.busi.service.IBusiCompanyGridService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 排放因子Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Service
public class BusiCompanyGridServiceImpl extends ServicePlusImpl<BusiCompanyGridMapper, BusiCompanyGrid, BusiCompanyGridVo> implements IBusiCompanyGridService {

    @Override
    public BusiCompanyGridVo queryById(Long id){
        return getVoById(id);
    }

    @Override
    public TableDataInfo<BusiCompanyGridVo> queryPageList(BusiCompanyGridBo bo) {
        PagePlus<BusiCompanyGrid, BusiCompanyGridVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<BusiCompanyGridVo> queryList(BusiCompanyGridBo bo) {
        return listVo(buildQueryWrapper(bo));
    }

    private LambdaQueryWrapper<BusiCompanyGrid> buildQueryWrapper(BusiCompanyGridBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<BusiCompanyGrid> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getSb1()), BusiCompanyGrid::getSb1, bo.getSb1());
        lqw.eq(StringUtils.isNotBlank(bo.getSb2()), BusiCompanyGrid::getSb2, bo.getSb2());
        lqw.eq(StringUtils.isNotBlank(bo.getSb3()), BusiCompanyGrid::getSb3, bo.getSb3());
        lqw.eq(StringUtils.isNotBlank(bo.getSb4()), BusiCompanyGrid::getSb4, bo.getSb4());
        lqw.eq(StringUtils.isNotBlank(bo.getSb5()), BusiCompanyGrid::getSb5, bo.getSb5());
        lqw.eq(StringUtils.isNotBlank(bo.getSb6()), BusiCompanyGrid::getSb6, bo.getSb6());
        lqw.eq(StringUtils.isNotBlank(bo.getSb7()), BusiCompanyGrid::getSb7, bo.getSb7());
        lqw.eq(StringUtils.isNotBlank(bo.getSb8()), BusiCompanyGrid::getSb8, bo.getSb8());
        lqw.eq(StringUtils.isNotBlank(bo.getSb9()), BusiCompanyGrid::getSb9, bo.getSb9());
        lqw.eq(StringUtils.isNotBlank(bo.getSb10()), BusiCompanyGrid::getSb10, bo.getSb10());
        lqw.eq(StringUtils.isNotBlank(bo.getSb11()), BusiCompanyGrid::getSb11, bo.getSb11());
        lqw.eq(StringUtils.isNotBlank(bo.getSb12()), BusiCompanyGrid::getSb12, bo.getSb12());
        lqw.eq(StringUtils.isNotBlank(bo.getSb13()), BusiCompanyGrid::getSb13, bo.getSb13());
        lqw.eq(StringUtils.isNotBlank(bo.getSb14()), BusiCompanyGrid::getSb14, bo.getSb14());
        lqw.eq(StringUtils.isNotBlank(bo.getSb15()), BusiCompanyGrid::getSb15, bo.getSb15());
        lqw.eq(StringUtils.isNotBlank(bo.getSb16()), BusiCompanyGrid::getSb16, bo.getSb16());
        lqw.eq(StringUtils.isNotBlank(bo.getSb17()), BusiCompanyGrid::getSb17, bo.getSb17());
        lqw.eq(StringUtils.isNotBlank(bo.getSb18()), BusiCompanyGrid::getSb18, bo.getSb18());
        lqw.eq(StringUtils.isNotBlank(bo.getSb19()), BusiCompanyGrid::getSb19, bo.getSb19());
        lqw.eq(StringUtils.isNotBlank(bo.getSb20()), BusiCompanyGrid::getSb20, bo.getSb20());
        lqw.eq(StringUtils.isNotBlank(bo.getSb21()), BusiCompanyGrid::getSb21, bo.getSb21());
        lqw.eq(StringUtils.isNotBlank(bo.getSb22()), BusiCompanyGrid::getSb22, bo.getSb22());
        lqw.eq(StringUtils.isNotBlank(bo.getSb23()), BusiCompanyGrid::getSb23, bo.getSb23());
        lqw.eq(StringUtils.isNotBlank(bo.getSb24()), BusiCompanyGrid::getSb24, bo.getSb24());
        lqw.eq(StringUtils.isNotBlank(bo.getSb25()), BusiCompanyGrid::getSb25, bo.getSb25());
        lqw.eq(StringUtils.isNotBlank(bo.getSb26()), BusiCompanyGrid::getSb26, bo.getSb26());
        lqw.eq(StringUtils.isNotBlank(bo.getSb27()), BusiCompanyGrid::getSb27, bo.getSb27());
        lqw.eq(StringUtils.isNotBlank(bo.getSb28()), BusiCompanyGrid::getSb28, bo.getSb28());
        lqw.eq(StringUtils.isNotBlank(bo.getSb29()), BusiCompanyGrid::getSb29, bo.getSb29());
        lqw.eq(StringUtils.isNotBlank(bo.getSb30()), BusiCompanyGrid::getSb30, bo.getSb30());
        lqw.eq(StringUtils.isNotBlank(bo.getSb31()), BusiCompanyGrid::getSb31, bo.getSb31());
        lqw.eq(StringUtils.isNotBlank(bo.getSb32()), BusiCompanyGrid::getSb32, bo.getSb32());
        lqw.eq(StringUtils.isNotBlank(bo.getSb33()), BusiCompanyGrid::getSb33, bo.getSb33());
        lqw.eq(StringUtils.isNotBlank(bo.getSb34()), BusiCompanyGrid::getSb34, bo.getSb34());
        lqw.eq(StringUtils.isNotBlank(bo.getSb35()), BusiCompanyGrid::getSb35, bo.getSb35());
        lqw.eq(StringUtils.isNotBlank(bo.getSb36()), BusiCompanyGrid::getSb36, bo.getSb36());
        lqw.eq(StringUtils.isNotBlank(bo.getSb37()), BusiCompanyGrid::getSb37, bo.getSb37());
        lqw.eq(StringUtils.isNotBlank(bo.getSb38()), BusiCompanyGrid::getSb38, bo.getSb38());
        lqw.eq(StringUtils.isNotBlank(bo.getSb39()), BusiCompanyGrid::getSb39, bo.getSb39());
        return lqw;
    }

    @Override
    public Boolean insertByBo(BusiCompanyGridBo bo) {
        BusiCompanyGrid add = BeanUtil.toBean(bo, BusiCompanyGrid.class);
        validEntityBeforeSave(add);
        boolean flag = save(add);
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    @Override
    public Boolean updateByBo(BusiCompanyGridBo bo) {
        BusiCompanyGrid update = BeanUtil.toBean(bo, BusiCompanyGrid.class);
        validEntityBeforeSave(update);
        return updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(BusiCompanyGrid entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return removeByIds(ids);
    }
}
